<?php  
class ModuleCategory extends Controller {
	function fetch() {	
		$config   =& $this->locator->get('config');
		$database =& $this->locator->get('database');
		$language =& $this->locator->get('language');
		$url      =& $this->locator->get('url');
		$template =& $this->locator->get('template');
		
		if ($config->get('category_status')) {	
			$language->load('extension/module/category.php');
		
			$view = $this->locator->create('template');

			$view->set('tpl', $template);
		
    		$view->set('heading_title', $language->get('heading_title'));

    		$category_data = array();

			$results = $database->getRows("select c.category_id, cd.name from category c left join category_description cd on (c.category_id = cd.category_id) where c.status = '1' and parent_id = '0' and language_id = '" . (int)$language->getId() . "' order by c.sort_order");

    		foreach ($results as $result) {
      			$category_data[] = array(
       				'name' => $result['name'],
        			'href' => $url->href('category', false, array('path' => $result['category_id']))
      			);
    		}

    		$view->set('categories', $category_data);
	
			return $view->fetch('module/category.tpl');
		}
  	}
}
?>
